在這個章節會使用到 NPM 來建置你的 Node 專案,初始化專案的同時也會介紹一些相關的套件協助你撰寫專案。
NPM (Nodejs Program Management) 是 NodeJS 平台的套件管理工具,你可以使用它來管理所安裝的套件,可以在這裡找到其他開發者所撰寫的套件,你也可以寫一個發布在上面供大家使用,下一步將介紹如何使用它開始一個專案
npm init 來初始專案Package-name - 專案名稱Version - 專案版本號 (1.0.0)Description - 專案的說明entry point - 起始程式的名稱(預設是 index.js)test command - 測試用的指令,可留白git repository - git 倉儲的位址,有 remote 會自動生成,沒有的話可留白但會有警告Keyword - 專案的關鍵字,可自訂亦可留白Author - 作者名稱,請寫下你自己的大名Licence - 授權,可註明授權種類,預設為( ISC )EX:
{
  "name": "foodstry-backend",
  "version": "1.0.0",
  "description": "The backend of foodstry which is the food management tool.",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ci-yang/foodstry-backend.git"
  },
  "author": "Ci Yang",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/ci-yang/foodstry-backend/issues"
  },
  "homepage": "https://github.com/ci-yang/foodstry-backend#readme"
}
scripts 可撰寫各種指令,除了預設的 start & test 可以直接使用
npm [command](e.g.npm start) 以外,其餘自訂的指令必須使用run npm [command](e.g.run npm lint)
使用 install 安裝你的套件
指令
npm install [package name]
注意事項:
node_modules  資料夾,存放所有安裝的套件-g 可以在全域的環境中安裝該套件uninstall

以下介紹利於開發的各項套件,我們也將在之後的張皆使用他們開發我們的專案